﻿using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Xml;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Text;
using Microsoft.Web.UI.WebControls;
using XMK.Tadong.Biz;

namespace XMK.Tadong.Web.TJ
{
    public partial class Data_AddWellToWelllistforobjectquery : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            // 在此处放置用户代码以初始化页面
            Response.ClearContent();
            Response.ClearHeaders();
            Response.Clear();
            Response.ContentType = "text/xml";
            Response.Charset = "GB2312";
            Response.Expires = 0;
            Response.Cache.SetCacheability(HttpCacheability.NoCache);

            string wellname = "";
            string id = "";
            StringBuilder wellstring = new StringBuilder();
            string name1 = Request.QueryString.Get("name");
            string nodetype1 = Request.QueryString.Get("nodetype");
            if (name1 == null || name1 == "")
                return;
            if (nodetype1 == null || nodetype1 == "")
                return;
            string strSql1 = "";
            string strSql = "";
            System.Xml.XmlDocument xdoc = new XmlDocument();

            //获取目标图层的ID号SQL语句
            if (nodetype1 == "1")//盆地
            {
                strSql = "select distinct basinid from gisbasin where basinname =" + "'" + name1 + "'";
            }
            if (nodetype1 == "2")//一级构造
            {
                strSql = "select distinct  tectonicid from  gistectonic where name =" + "'" + name1 + "'";
            }

            //获取盆地ID号
            //JrscSoft.DataService.DataService dService = new JrscSoft.DataService.DataService();
            //连接数据库 
            YQCJDBLL bll = new YQCJDBLL();
            try
            {

                //OracleDataReader reader = dService.GetDataReader(strSql);
                DataTable dt = bll.QueryData(strSql);
                //while (reader.Read())
                //{
                for (int k = 0; k < dt.Rows.Count; k++)
                {
                    if (nodetype1 == "1")
                        id = dt.Rows[k]["basinid"].ToString();
                    //id = reader["basinid"].ToString().Trim();
                    if (nodetype1 == "2")
                        id = dt.Rows[k]["tectonicid"].ToString();
                    //id = reader["tectonicid"].ToString().Trim();
                    //}
                    //reader.Close();
                }
            }
            catch (Exception er)
            {
                System.Diagnostics.Debug.WriteLine(er.ToString());
            }


            //获取目标图层的所有井位SQL语句
            if (nodetype1 == "1")//盆地
            {
                strSql1 = "select distinct wellid,basinid,jh from giswell where basinid =" + "'" + id + "'";
            }
            if (nodetype1 == "2")//一级构造
            {
                strSql1 = "select distinct wellid, tectonicid,jh from giswell where  tectonicid =" + "'" + id + "'";
            }

            //获取盆地上所有井位
            try
            {
                //OracleDataReader reader = dService.GetDataReader(strSql1);
                DataTable dt1 = bll.QueryData(strSql1);
                //while (reader.Read())
                //{
                for (int j = 0; j < dt1.Rows.Count; j++)
                {
                    wellname = id = dt1.Rows[j]["jh"].ToString();// id = dt.Rows[0]["basinid"].ToString(); reader["jh"].ToString().Trim();
                    wellstring.Append(wellname);
                    wellstring.Append(",");
                }
                //}
                //reader.Close();

            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.Write(ex.Message);
            }

            //获取井列表
            int i = wellstring.Length;
            if (i != 0)
            {
                wellstring = wellstring.Remove(i - 1, 1);
            }
            //返回井列表
            try
            {
                XmlElement xeLayer = xdoc.CreateElement("welllist");
                xdoc.AppendChild((XmlNode)xeLayer);
                XmlElement elem = xdoc.CreateElement("wellS");
                xeLayer.AppendChild((XmlNode)elem);
                elem.SetAttribute("wells", wellstring.ToString());
                elem.InnerText = wellstring.ToString();

            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.Write(ex.Message);
            }
            if (xdoc != null)
            {
                xdoc.Save(Response.OutputStream);
            }
        }
    }
}